package com.atguigu.realtime.function;

import com.atguigu.realtime.util.MyKeyWordUtil;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

import java.util.Set;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/4/27 11:31
 */
// 告诉 flink row的内部结构: 几列, 每列的类型
@FunctionHint(output = @DataTypeHint("ROW<k string>"))
public class KeywordUdtf extends TableFunction<Row> {
    public void eval(String text) {
        Set<String> ws = MyKeyWordUtil.analyzer(text);
        for (String w : ws) {
            // 一进多出
            collect(Row.of(w));
        }
    }
}
